# _*_ coding: UTF-8 _*_
# 开发人员  ：LuoWen_Top
# 开发时间  ：2020/8/31 15:06
# 文件名称  ：import_category_jfz_data.py
# 开发工具  ：PyCharm


"""
    导入金福尊大类数据， 只包含两个级别。
"""

import os
import sys

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + "../")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MxShop.settings")

import django

django.setup()

# 必须先初始化django的相关配置
from goods.models import GoodsCategory
# from db_tools.data.category_data import row_data
from db_tools.data.jfz_category_data import row_data

for lev1_cat in row_data:
    lev1_instance = GoodsCategory()
    lev1_instance.code = lev1_cat['code']
    lev1_instance.name = lev1_cat['name']
    lev1_instance.category_type = 1
    lev1_instance.save()

    for lev2_cat in lev1_cat['sub_categorys']:
        lev2_instance = GoodsCategory()
        lev2_instance.code = lev2_cat['code']
        lev2_instance.name = lev2_cat['name']
        lev2_instance.parent_category = lev1_instance
        lev2_instance.category_type = 2
        lev2_instance.save()
